//
// Created by Symps on 2025/11/15.
//

#include <algorithm>
#include <iostream>
#include <vector>
using std::endl;
using std::string;
using std::cout;

std::string longestPalindrome(std::string s) {
    int n = s.size();
    int maxBegin = 0;
    int maxLen = 0;
    for (int i = 0; i < n; ++i) {
        int left = i - 1, right = i + 1;
        while (right < n && s[i] == s[right]) {
            ++right;
        }
        while (left >= 0 && right < n && s[left] == s[right]) {
            --left;
            ++right;
        }
        int len = right - left - 1;
        if (len > maxLen) {
            maxLen = len;
            maxBegin = left + 1;
        }
    }
    return s.substr(maxBegin, maxLen);
}

void test1() {//"babad"
    std::string hui_wen = longestPalindrome("cbbd");
    std::cout << hui_wen << std::endl;
}

void test2() {
    std::string str = "1";
    // std::to_integer<int>(str);
    int num = std::stoi(str);
    std::cout << num << std::endl;
    str += 'a';
    std::cout << str << std::endl;
    std::cout << std::string(str.rbegin(), str.rend()) << std::endl;
    std::reverse(str.begin(), str.end());
    std::cout << str << std::endl;
}

string add(const string& num1, const string& num2) {
    string ret;
    int i = num1.size() - 1, j = num2.size() -  1;
    int carry = 0;
    while (i >= 0 || j >= 0 || carry) {
        int S = (i >= 0 ? num1[i] : '0') + (j >= 0 ? num2[j] : '0') - 2 * '0' + carry;
        carry = S / 10;
        ret += S % 10 + '0';
        --i;
        --j;
    }
    reverse(ret.begin(), ret.end());
    return ret;
}

string multiply1(const string& num1, const string& num2) {
    if (num1 == "0" || num2 == "0") {
        return "0";
    }

    string ret = "0";
    int C = 0;
    int len1(num1.size()), len2(num2.size());
    for (int i = len1 - 1; i >= 0; --i) {
        string temp;
        for (int j = len2 - 1; j >= 0; --j) {
            int P((num1[i] - '0') * (num2[j] - '0') + C);
            C = P / 10;
            temp += P % 10 + '0';
        }
        if (C) {
            temp += C + '0';
        }
        reverse(temp.begin(), temp.end());
        int offset(len1 - 1 - i);
        while (offset -- > 0) {
            temp += '0';
        }
        ret = add(ret, temp);
        C = 0;
    }
    return ret;
}

void test3() {
    // string num1 = "123", num2 = "4596";
    // std::cout << add(num1, num2) << std::endl;

    string num1 = "123", num2 = "456";
    std::cout << multiply1(num1, num2) << std::endl;
}

string multiply(const string& num1, const string& num2) {
    if (num1 == "0" || num2 == "0") {
        return "0";
    }

    int len1(num1.size()), len2(num2.size());
    int len3(len1 + len2);
    std::vector carrys(len3, 0);

    for (int i(len2 - 1); i >= 0; --i) {
        for (int j(len1 - 1); j >= 0; --j) {
            carrys[i + j + 1] += (num1[j] - '0') * (num2[i] - '0');
        }
    }
    for (int i(len3 - 1); i > 0; --i) {
        carrys[i - 1] += carrys[i] / 10;
        carrys[i] %= 10;
    }
    string ret;
    for (auto& c : carrys) {
        if (!(c == 0 && ret.empty())) {
            ret += c % 10 + '0';
        }
    }
    return ret;
}

void test4() {
    string num1 = "2", num2 = "6";
    cout << multiply(num1, num2) << endl;
}

int main() {
    // test1();
    // test2();
    // test3();
    test4();
    return 0;
}
